﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using HZU.ZP.Data.Impl;
using Microsoft.AspNetCore.Authentication.Cookies;
using HZU.ZP.Data.Interfaces;
using HZU.ZP.Data.Interfaces.Resume;
using HZU.ZP.Data.Impl.Resume;
using HZU.ZP.Domain.IService;
using HZU.ZP.Domain.ServiceImpl.PCSvc;
using HZU.ZP.Domain.IService.Resume;
using HZU.ZP.Domain.ServiceImpl.PCSvc.Resume;
using HZU.ZP.Help;

namespace HZU.ZP
{
    public class Startup
    {
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public IConfiguration Configuration { get; set; }
        public Startup()
        {
            var builder = new ConfigurationBuilder()
                .SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile("AppSettings.json");
            Configuration = builder.Build();
        }
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddEntityFrameworkSqlServer().AddDbContext<EFCoreDbContext>(
                options => options.UseSqlServer(Configuration["database:connection"], b => b.UseRowNumberForPaging())
                );
            services.AddSignalR();

            services.AddMvc();

            //添加认证Cookie信息
            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
                .AddCookie(options =>
                {
                    options.LoginPath = new PathString("/Home/Login");
                    options.AccessDeniedPath = new PathString("/Home/Denied");
                });

            //仓储DI
            services.AddScoped<IAwardDao, AwardDao>();
            services.AddScoped<IEducationExperienceDao, EducationExperienceDao>();
            services.AddScoped<IInformationDao, InformationDao>();
            services.AddScoped<IJobIntentionDao, JobIntentionDao>();
            services.AddScoped<IMasterSkillDao, MasterSkillDao>();
            services.AddScoped<IProjectExperienceDao, ProjectExperienceDao>();
            services.AddScoped<ISelfEvaluationDao, SelfEvaluationDao>();
            services.AddScoped<IAdminDao, AdminDao>();
            services.AddScoped<IApplicantDao, ApplicantDao>();
            services.AddScoped<IApplyRecordDao, ApplyRecordDao>();
            services.AddScoped<ICollectRecordDao, CollectRecordDao>();
            services.AddScoped<ICommentDao, CommentDao>();
            services.AddScoped<ICompanyDao, CompanyDao>();
            services.AddScoped<ICompanyInformationDao, CompanyInformationDao>();
            services.AddScoped<ICompayPictureDao, CompayPictureDao>();
            services.AddScoped<IMessageDao, MessageDao>();
            services.AddScoped<INoticeDao, NoticeDao>();
            services.AddScoped<IPositionDao, PositionDao>();
            services.AddScoped<IZanDao, ZanDao>();

            //服务DI
            services.AddTransient<IAdminService, AdminService>();
            services.AddTransient<IApplicantService,ApplicantService>();
            services.AddTransient<IApplyRecordService, ApplyRecordService>();
            services.AddTransient<ICollectRecordService, CollectRecordService>();
            services.AddTransient<ICommentService, CommentService>();
            services.AddTransient<ICompanyService, CompanyService>();
            services.AddTransient<ICompanyInformationService, CompanyInformationService>();
            services.AddTransient<ICompayPictureService, CompayPictureService>();
            services.AddTransient<IMessageService, MessageService>();
            services.AddTransient<INoticeService, NoticeService>();
            services.AddTransient<IPositionService, PositionService>();
            services.AddTransient<IZanService, ZanService>();
            services.AddTransient<IAwardService, AwardService>();
            services.AddTransient<IEducationExperienceService, EducationExperienceService>();
            services.AddTransient<IInformationService, InformationService>();
            services.AddTransient<IJobIntentionService, JobIntentionService>();
            services.AddTransient<IMasterSkillService, MasterSkillService>();
            services.AddTransient<IProjectExperienceService, ProjectExperienceService>();
            services.AddTransient<ISelfEvaluationService, SelfEvaluationService>();

        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Applicant/Error");
            }

            app.UseStaticFiles();

            app.UseAuthentication();

            app.UseSignalR(routes =>
            {
                routes.MapHub<MyHub>("/MyHub");
            });

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Applicant}/{action=Login}/{id?}"
                    );
            });
        }
    }
}
